package com.muxue.module.ai.controller.model;


import com.muxue.common.core.model.CommonResult;
import com.muxue.common.core.page.PageResult;
import com.muxue.module.ai.controller.model.vo.apikey.AiApiKeyPageReqVO;
import com.muxue.module.ai.controller.model.vo.apikey.AiApiKeyRespVO;
import com.muxue.module.ai.controller.model.vo.apikey.AiApiKeySaveReqVO;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.muxue.common.exception.ServiceException.exception;
import static com.muxue.common.utils.system.CollectionUtils.convertList;
import static com.muxue.module.ai.model.enums.ErrorCodeConstants.CHAT_CONVERSATION_NOT_EXISTS;


@Tag(name = "管理后台 - AI API 密钥")
@RestController
@RequestMapping("/ai/api-key")
@Validated
public class AiApiKeyController {

//    @Resource
//    private AiApiKeyService apiKeyService;

    @PostMapping("/create")
    @Operation(summary = "创建 API 密钥")
    @PreAuthorize("@ss.hasPermission('ai:api-key:create')")
    public CommonResult<Long> createApiKey(@Valid @RequestBody AiApiKeySaveReqVO createReqVO) {
        throw exception(CHAT_CONVERSATION_NOT_EXISTS);
    }

    @PutMapping("/update")
    @Operation(summary = "更新 API 密钥")
    @PreAuthorize("@ss.hasPermission('ai:api-key:update')")
    public CommonResult<Boolean> updateApiKey(@Valid @RequestBody AiApiKeySaveReqVO updateReqVO) {
        throw exception(CHAT_CONVERSATION_NOT_EXISTS);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除 API 密钥")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('ai:api-key:delete')")
    public CommonResult<Boolean> deleteApiKey(@RequestParam("id") Long id) {
        throw exception(CHAT_CONVERSATION_NOT_EXISTS);
    }

    @GetMapping("/get")
    @Operation(summary = "获得 API 密钥")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('ai:api-key:query')")
    public CommonResult<AiApiKeyRespVO> getApiKey(@RequestParam("id") Long id) {
        throw exception(CHAT_CONVERSATION_NOT_EXISTS);
    }

    @GetMapping("/page")
    @Operation(summary = "获得 API 密钥分页")
    @PreAuthorize("@ss.hasPermission('ai:api-key:query')")
    public CommonResult<PageResult<AiApiKeyRespVO>> getApiKeyPage(@Valid AiApiKeyPageReqVO pageReqVO) {
        throw exception(CHAT_CONVERSATION_NOT_EXISTS);
    }

//    @GetMapping("/simple-list")
//    @Operation(summary = "获得 API 密钥分页列表")
//    public CommonResult<List<AiChatModelRespVO>> getApiKeySimpleList() {
//        List<AiApiKeyDO> list = apiKeyService.getApiKeyList();
//        return success(convertList(list, key -> new AiChatModelRespVO().setId(key.getId()).setName(key.getName())));
//    }

}